package org.example.service.fileprocessor;



import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.springframework.stereotype.Component;
import java.io.InputStream;

@Component
public class PdfFileProcessor implements FileProcessor {

    @Override
    public String extractText(InputStream inputStream) throws Exception {
        try (PDDocument document = PDDocument.load(inputStream)) {
            PDFTextStripper stripper = new PDFTextStripper();
            stripper.setSortByPosition(true);
            return stripper.getText(document);
        }
    }

    @Override
    public boolean supports(String contentType) {
        return "application/pdf".equals(contentType);
    }
}